package com.wei.czz.common.enums.annex;

import com.wei.czz.common.dto.common.NameValue;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * Created by IntelliJ IDEA.
 *
 * @author wyw
 * date: 2024-01-18 17:10:36
 * className: AnnexFieldCompareModeEnum
 * version: 1.0
 * description:
 */
@Getter
@AllArgsConstructor
public enum AnnexFieldCompareModeEnum {

    /*
        比较方式[0-等于 1-不等于 2-相等 3-不相等 4-数值包含 5-数值不包含 6-字符串包含 7-字符串不包含 8-数值区间 9-时间区间 10-日期区间]
     */
    EQUALS_NUMBER(0, "等于"),
    NOT_EQUALS_NUMBER(1, "不等于"),

    EQUALS_STRING(2, "等于"),
    NOT_EQUALS_STRING(3, "不等于"),

    CONTAIN_NUMBER(4, "包含"),
    NOT_CONTAIN_NUMBER(5, "不包含"),

    CONTAIN_STRING(6,"包含"),
    NOT_CONTAIN_STRING(7, "不包含"),

    RANGE_NUMBER(8, "区间"),

    RANGE_DATETIME(9, "时间区间"),
    RANGE_DATE(10, "日期区间"),

    ;

    /**
     * 值
     */
    private final Integer value;

    /**
     * 名称
     */
    private final String name;

    /**
     * 获取枚举对象
     * @param value 值
     * @return 枚举对象
     */
    public static AnnexFieldCompareModeEnum get(Integer value) {
        for (AnnexFieldCompareModeEnum annexFieldCompareModeEnum : values()) {
            if (annexFieldCompareModeEnum.value.equals(value)) {
                return annexFieldCompareModeEnum;
            }
        }
        return null;
    }

    /**
     * 获取名称
     * @param value 值
     * @return 名称
     */
    public static String getName(Integer value) {
        for (AnnexFieldCompareModeEnum annexFieldCompareModeEnum : values()) {
            if (annexFieldCompareModeEnum.value.equals(value)) {
                return annexFieldCompareModeEnum.name;
            }
        }
        return "";
    }

    /**
     * 获取枚举列表
     */
    public static List<NameValue<Integer>> getList() {
        return Stream.of(values())
                .map(annexFieldCompareModeEnum ->
                        new NameValue<>(annexFieldCompareModeEnum.name, annexFieldCompareModeEnum.value)
                )
                .collect(Collectors.toList());
    }

}
